package com.semanticweb.project.api;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.sql.SDBConnection;
import com.hp.hpl.jena.sdb.store.DatabaseType;

public interface Ontology {

    /**
     * Loads Database driver so SDB can use it to connect to database.
     * 
     * @param dbDriverClass
     *            - full name (including package) of database driver class.
     */
    public void loadDatabaseDriver(String dbDriverClass);

    /**
     * Establishes connection to SQL database.
     * 
     * @param url
     *            - url of database
     * @param name
     *            - username for logging on to database
     * @param pw
     *            - password for logging on to database
     * @return object representing connection to database
     */
    public SDBConnection connectToDatabase(String url, String name, String pw);

    /**
     * Creates ontology store connected to database allowing data manipulation.
     * 
     * @param connection
     *            - connection to database
     * @param dbType
     *            - type of database
     * @return object representing ontology store
     */
    public Store connectToStore(SDBConnection connection, DatabaseType dbType);

    /**
     * Loads ontology model from file with desired namespace.
     * 
     * @param filePath
     *            - Absolute file path to ontology model
     * @param namespace
     *            - Default namespace for model
     */
    public OntModel loadOntologyFromFile(String filePath, String namespace);

    /**
     * Saves model to database.
     * 
     */
    public void saveModel();

    /**
     * Closes database connection.
     * 
     */
    public void closeDBConnection();

    /**
     * Creates default (empty) database model.
     * 
     */
    public void createDB();

    /**
     * Destroys data in database (empties tables).
     * 
     */
    public void destroyDB();

    /**
     * Returns <code>true</code> if database exists, otherwise <code>false</code>. <br>
     * Database exists if connection is successfully established <br>
     * and if default database model is created <br>
     * (you can create this model by using <code>createDB()</code> method).
     * 
     * @return <code>true</code> if database exists, otherwise <code>false</code>.
     */
    public boolean dbExists();

    /**
     * Store is one RDF data set instance.
     * 
     * @return Database store.
     */
    public Store getStore();

    /**
     * OntModel is enchanted view of a Jena model that is known to contain ontology data, <br>
     * under a given ontology vocabulary(such as OWL).
     * 
     * @return ontology model.
     */
    public OntModel getModel();

    /**
     * Creates individual and adds it to the ontology model. <br>
     * Parameters are unique URLs of resources (if they are relative, they will be concatenated to URL)
     * 
     * @param individualClass
     *            - class of individual
     * @param individualName
     *            - name of individual
     */
    public void createIndividual(String individualClass, String individualName);

    /**
     * Connects subject to object via specified predicate. <br>
     * Parameters are unique URLs of resources (if they are relative, they will be concatenated to URL)
     * 
     * @param subject
     *            - subject name
     * @param predicate
     *            - predicate name
     * @param object
     *            - object name
     */
    public void connectIndividuals(String subject, String predicate, String object);

    /**
     * Adds label to individual. <br>
     * Parameter "individualName" is unique URL of resource(if it's relative, it will be concatenated to URL)
     * 
     * @param individualName
     *            - name of individual
     * @param label
     *            - label
     */
    public void addLabel(String individualName, String label);

    /**
     * Executes SPARQL SELECT query.
     * 
     * @param query
     *            - SPARQL query
     * @return result set of query execution
     */
    public ResultSet query(final String query);

    /**
     * Executes SPARQL SELECT query and returns array of results of property specified in item parameter.
     * 
     * @param query
     *            - SPARQL query to be executed
     * @param item
     *            - parameter which values will be returned
     * @return String array representing query result
     */
    public String[] queryStr(final String query, final String item);

    /**
     * Executes SPARQL ASK query.
     * 
     * @param query
     *            - SPARQL query
     * @return - result of SPARQL ASK query - true or false.
     */
    public boolean askQuery(String query);

    /**
     * Get Label from resource
     * 
     * @param resource
     *            - resource URI
     * @return - label
     */
    public String getLabel(String resource);
}
